package cn.net.ecode.modules.sys.web;

import java.util.Enumeration;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.net.ecode.common.web.BaseController;

import com.google.common.collect.Maps;

/**
 * 跳转controller 不需要权限
 * @title: RedirectController.java
 * @package cn.net.ecode.bes.web
 * @author 刘保全
 * @date 2014-6-23 上午8:50:44
 * @version v1.0
 */
@Deprecated
@Controller
@RequestMapping(value = "${adminPath}/sys/redirect")
public class RedirectController extends BaseController {

	/***
	 * 登陆用户权限，跳转页面
	 * 
	 * @param entity
	 * @param model
	 * @return
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = "")
	public String redirect(HttpServletRequest request, Model model) {

		// 跳转JSP
		String redirectJSP = request.getParameter("redirectJSP");
		// 传递的参数
		@SuppressWarnings("unchecked")
		Enumeration<String> param = request.getParameterNames();
		Map<String, String> mapParam = Maps.newHashMap();
		while (param.hasMoreElements()) {
			String name = param.nextElement();
			String value = request.getParameter(name);
			/*
			 * try { value = new String(value.getBytes("ISO-8859-1"), "UTF-8");
			 * } catch (Exception e) { }
			 */
			mapParam.put(name, value);
		}
		// 移除参数
		mapParam.remove("redirectJSP");
		mapParam.remove("parentTabPageId");
		mapParam.remove("tabPageId");

		// debug输出，用于调试
		logger.debug("redirect jsp:" + redirectJSP);
		logger.debug("param:" + mapParam);

		// 将参数绑定到model
		model.addAttribute("mapParam", mapParam);
		// 返回跳转的页面
		return redirectJSP;
	}

}
